/**
 * 描述: 产品图文列表页
 *
 * @author yangshuangping
 * @since 2021/12/09 17:41
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;
    let laypage = layui.laypage;
    let layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        defaultToolbar: [],
        limit: json.pageSize,
        height: 'full-149'
    });
    laypage.render(layui.$.extend({limits: [10, 20, 30, 40, 50, 100]}, zmnPage.laypageOptions(json)));

    let ids = new Array();
    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.graphicId);
    });

    // 修改排序
    table.on("edit(zmn-table)", function (obj) {
        if (zmnUtil.isEmptyNull(obj.data.sort)) {
            return false;
        }
        zmnPage.laySortPositiveInteger(obj.value, "/graphic/updateSort.action",
            obj.data.graphicId, 0, 1000, function () {
                if (obj.data.sort.length > 8) {
                    return "排序字段长度不能超过8位";
                }
            });
    });

    form.on("switch(chk_status_flag)", function (obj) {
        let url = "/graphic/updateStatus.action";
        let graphicId = obj.elem.getAttribute("key");
        let status = obj.elem.checked ? 2 : 1;
        switch (status) {
            case 1:
                zmnPage.ajaxSimple(url, {ids: graphicId, status: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {ids: graphicId, status: 2}, 1000);
                break;
        }
        setTimeout(function () {
            location.reload(true);
        }, 3000);
    });

    //对外暴露的接口
    exports('plat_product_graphic_list', {});
});
let $ = layui.$;

function addAndModifyGraphic(productId, graphicId) {
    layer.open({
        type: 2,
        title: zmnUtil.isEmptyNull(graphicId) ? "新增" : "修改",
        area: ['610px', '662px'],
        content: '/graphic/addEditView.action?productId=' + productId + "&graphicId=" + graphicId
    });
}

/**
 * 预览图片
 * @param element
 */
function thePreviewImage(element) {
    let image = new Image();
    image.src = document.getElementById(element).src;
    let imgHtml = "<img src='" + image.src + "' width='100%' height='100%'/>";
    layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
        area: [600 + 'px', 300 + 'px'],
        shadeClose: true,
        scrollbar: false,
        title: "",
        content: imgHtml,
        cancel: function () {
        }
    });
}

